package org.example.ioc.pro2_ioc;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.sql.Connection;
import java.sql.SQLException;

public class App1 {
    public static void main(String[] args) throws InterruptedException, SQLException {
        // 创建容器
       ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        // 从容器中获取Bean
         Product product = context.getBean(Product.class);
         System.out.println(product);


//
//       ThreadPoolExecutor executor = (ThreadPoolExecutor) context.getBean("tpe");
//        executor.execute(new Runnable() {
//            @Override
//            public void run() {
//                while(true){
//                    try {
//                        Thread.sleep(1000);
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                    System.out.println(new Date());
//                }
//            }
//        });
//        for (int i = 0; i < 100; i++) {
//            System.out.println("我是主线程》》》");
//            Thread.sleep(2000);
//        }


        DruidDataSource dds= (DruidDataSource) context.getBean("ds");
        Connection con=dds.getConnection();
        System.out.println(con);



    }
}
